package io.ganguo.chat.route.biz.service.impl;

import io.ganguo.chat.route.biz.entity.Message;
import io.ganguo.chat.route.biz.repository.MessageRepository;
import io.ganguo.chat.route.biz.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Tony on 2/23/15.
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    MessageRepository messageRepository;

    @Override
    public List<Message> findByFrom(Long from) {
        return messageRepository.findByFrom(from);
    }

    @Override
    public List<Message> findByTo(Long to) {
        return messageRepository.findByTo(to);
    }

    public List<Message> findByToOrderByCreateAtDesc(Long to) {
        return messageRepository.findByToOrderByCreateAtDesc(to);
    }

    @Override
    public List<Message> findByToOrderByCreateAtAsc(Long to) {
        return messageRepository.findByToOrderByCreateAtAsc(to);
    }

    public void save(Message message) {
        messageRepository.save(message);
    }
}
